package crmsystem.com.controller;

import java.util.Arrays;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import crmsystem.com.entity.DepartmentEntity;
import crmsystem.com.service.DepartmentService;
import crmsystem.com.utils.PageUtils;
import crmsystem.com.utils.R;

import javax.validation.Valid;


/**
 * 
 *
 * @author zhugaowei
 * @email 1912431877@qq.com
 * @date 2021-01-07 12:48:11
 */
@RestController
@RequestMapping("/department")
public class DepartmentController {
    @Autowired
    private DepartmentService departmentService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("com:department:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = departmentService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("com:department:info")
    public R info(@PathVariable("id") Integer id){
		DepartmentEntity department = departmentService.getById(id);

        return R.ok().put("department", department);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("com:department:save")
    public R save(@Valid @RequestBody DepartmentEntity department){
		departmentService.save(department);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("com:department:update")
    public R update(@Valid @RequestBody DepartmentEntity department){
		departmentService.updateById(department);

        return R.ok();
    }

    /**
     * 批量删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("com:department:delete")
    public R delete(@RequestBody Integer[] ids){
		departmentService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     *根据id删除
     */
    @RequestMapping("/delete/{id}")
    //@RequiresPermissions("com:business:delete")
    public R deleteById(@PathVariable("id") Integer id){
        departmentService.removeById(id);
        return R.ok();
    }
}
